* Created by Ashish Shenoy 
* Contact: shenoy@ucdavis.edu
* This do-file generates all Tables and Figures in Striving to Revive Pulses in India with Extension, Input Subsidies, and Output Price Supports

* Define this:
global head = "."

* Necessary packages to install
ssc install estout
ssc install coefplot
ssc install ietoolkit
ssc install ebalfit
ssc install qqvalue
	net from http://www.stata.com
    net cd users
    net cd vwiggins
    net install grc1leg

* Graph settings
* Fontface: https://fontlibrary.org/en/font/cmu-serif
graph set window fontface "CMU Serif"
set scheme s2color

* Define relative locations in the replication package
global eval_do = "$head/do-files"

global out_tables="$head/Tables"
global out_figures="$head/Figures"
global out_data="$head/Data/Processed"

global raw_files="$head/Data/Raw"
global admin_data="$raw_files/Admin"

global y1="$raw_files/Surveys/Year 1"
global y2="$raw_files/Surveys/Year 2"
global y3="$raw_files/Surveys/Year 3"

global k1="$y1/Kharif 2017"
global k2="$y2/Kharif 2018"
global k3="$y3/Kharif 2019"

global r1="$y1/Rabi 2018"
global r2="$y2/Rabi 2019"
global r3="$y3/Rabi 2020"

global bdm_raw="$raw_files/BDM"
global fpc_raw="$raw_files/FPC"
global shrug="$raw_files/SHRUG"

cd "$head/"

*0. Build a survey roster file
	
	do "$eval_do/make_survey_roster.do"
	
*1. Build outcome files from survey data for analysis
	
	do "$eval_do/make_survey_production.do"
	do "$eval_do/make_survey_profits.do"
	do "$eval_do/make_survey_patterns.do"
	do "$eval_do/make_survey_stocks.do"
	do "$eval_do/make_survey_consumption.do"
	
*2. Build outcome files from BDM seed auction and FPC admin data for analysis 
	
	do "$eval_do/make_bdm_demand.do"
	do "$eval_do/make_fpc_outcomes.do"

*3. Generate randomization balance tables  
	
	* Tables 1, 2, S3
	* NOTE: Output formatted by hand a little to look prettier
	do "$eval_do/tables_balance.do"
	
*4. Generate input experiment regressions and tables

	* Define some stuff common to all input regressions/analysis
	global B_coef B_y1_t B_y2_t B_y3_t
	global B_main B_y1_t B_y2_t B_y3_t B_y2 B_y3
	global controls hh_size i.caste i.block i.m_education bl_pulse_prev bl_wealth_win5
	* Variables coming from Rabi 2020 survey (for drop ever/srvy)
	global Rvars pulse_adopt3 pulse_area3 pulse_prod_win52 pulse_prod_win53 pulse_yield3 earn_sales_win5 

	* Main tables and robustness 
	* Tables: 3, 5, S6, S7, S8, S9-S34 (NOTE: Tables S9-S34 not well-numbered)
	* Figures: 6, S3, S9-S13
	* NOTE: This file contains a flag for standardizing by control mean or standard deviations
	* NOTE: It must be run again independently to generate both Figures 6 and S3
	* NOTE: Also displays PCA construction, but Table S5 is hand-constructed
	do "$eval_do/tables_input_regressions.do"
	
	* Adoption and area figure
	* Figure 4
	do "$eval_do/tables_adoption_figure.do"
	
	* Seed auction demand analysis
	* Table 4 and Figure 5
	do "$eval_do/tables_bdm_outcomes.do"
	
	* Double lasso and entropy balancing robustness
	* Figures S4-S8
	do "$eval_do/tables_appendix_covariates.do"
	
	* Adoption patterns (monocropping v. mixed/border)
	* Figure S2 and Table S4
	do "$eval_do/tables_input_patterns.do"
	
*5. Generate output experiment results

	* Table 6
	do "$eval_do/tables_output_regressions.do"